package work.shyk.gaas;

import java.util.Scanner;

/**
 * description: <br>
 * createTime: 2020/11/514:43 <br>
 *
 * @author zzh
 */
public class Main {
    public static int getLastWordLength(String str) {
        String temp = str.trim();
        int lastIndex = temp.lastIndexOf(" ");
        if(lastIndex >= 0) {
            return temp.substring(lastIndex + 1).length();
        }
        return temp.length();
    }

    public static int countCharInString(String str, char c) {
        String temp = str.toLowerCase();
        char smallC = Character.toLowerCase(c);
        int count = 0;
        for (char c1 : temp.toCharArray()) {
            if(c1 == smallC) {
                count++;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个字符串，回车结尾，再输入要计算的字符：");
        String input = scanner.nextLine();
        char c = scanner.next().charAt(0);
        System.out.println("输入的字符在字符串中出现的次数为:" + countCharInString(input, c));
    }
}
